<script lang="ts" setup>
import { computed } from "vue";
import { equip2 } from "@/configs/equip";
import { getShowValue } from "@/utils/equip";

interface Props {
    equip2V2: Equip.EquipInfo;
}
const props = withDefaults(defineProps<Props>(), {});
const airTemperatureV2 = computed(() => {
    const dtAI = props.equip2V2.dtAI.find((v) => v.index == equip2.airTemperatureIndex);
    return getShowValue(dtAI?.value || 0, dtAI?.x1 || 0, dtAI?.x2 || 0, dtAI?.y1 || 0, dtAI?.y2 || 0);
});
const airHumidityV2 = computed(() => {
    const dtAI = props.equip2V2.dtAI.find((v) => v.index == equip2.airHumidityIndex);
    return getShowValue(dtAI?.value || 0, dtAI?.x1 || 0, dtAI?.x2 || 0, dtAI?.y1 || 0, dtAI?.y2 || 0);
});
const soilTemperatureV2 = computed(() => {
    const dtAI = props.equip2V2.dtAI.find((v) => v.index == equip2.soilTemperatureIndex);
    return getShowValue(dtAI?.value || 0, dtAI?.x1 || 0, dtAI?.x2 || 0, dtAI?.y1 || 0, dtAI?.y2 || 0);
});
const soilHumidityV2 = computed(() => {
    const dtAI = props.equip2V2.dtAI.find((v) => v.index == equip2.soilHumidityIndex);
    return getShowValue(dtAI?.value || 0, dtAI?.x1 || 0, dtAI?.x2 || 0, dtAI?.y1 || 0, dtAI?.y2 || 0);
});
</script>

<template>
    <section>
        <h3>
            <svg class="icon" aria-hidden="true"><use xlink:href="#icon-zhiwu"></use></svg>
            <b>环境监控</b>
            <span>Huan Jing Jian Kong</span>
        </h3>
        <hr class="to-right" />
        <div class="content">
            <div class="left">
                <div class="item">
                    <h4>空气温度</h4>
                    <p>
                        <b>{{ airTemperatureV2 }}</b>
                        <span>℃</span>
                    </p>
                </div>
                <hr class="to-left" />
                <div class="item">
                    <p>
                        <b>{{ airHumidityV2 }}</b>
                        <span>%</span>
                    </p>
                    <h4>空气湿度</h4>
                </div>
            </div>
            <div class="center">
                <div class="inner">
                    <svg class="icon" aria-hidden="true"><use xlink:href="#icon-zhiwu"></use></svg>
                </div>
            </div>
            <div class="right">
                <div class="item">
                    <h4>土壤温度</h4>
                    <p>
                        <b>{{ soilTemperatureV2 }}</b>
                        <span>℃</span>
                    </p>
                </div>
                <hr class="to-right" />
                <div class="item">
                    <p>
                        <b>{{ soilHumidityV2 }}</b>
                        <span>%</span>
                    </p>
                    <h4>土壤湿度</h4>
                </div>
            </div>
        </div>
    </section>
</template>

<style lang="scss" scoped>
@use "../styles/section.scss";
section {
    .content {
        .left,
        .right {
            width: 110px;
            display: flex;
            flex-direction: column;
            row-gap: 10px;
            .item {
                display: flex;
                flex-direction: column;
                row-gap: 10px;
                h4 {
                    color: var(--primary-color);
                    font-size: 14px;
                }
                p {
                    display: flex;
                    align-items: flex-end;
                    column-gap: 4px;
                    b {
                        color: #fff;
                        font-size: 20px;
                        font-weight: normal;
                    }
                    span {
                        color: #999;
                        font-size: 12px;
                        font-weight: normal;
                    }
                }
            }
            &.left {
                hr {
                    margin-left: -10px;
                }
            }
            &.right {
                align-items: flex-end;
                hr {
                    margin-right: -10px;
                }
                .item {
                    align-items: flex-end;
                }
            }
        }
        .center {
            flex-shrink: 0;
            width: 120px;
            height: 120px;
            border-radius: 50%;
            border: 2px solid var(--darken-primary-color);
            box-shadow: 0 0 20px 3px var(--darken-primary-color) inset;
            display: flex;
            justify-content: center;
            align-items: center;
            .inner {
                width: 80%;
                height: 80%;
                display: flex;
                justify-content: center;
                align-items: center;
                border: 2px solid var(--primary-color);
                box-shadow: 0 0 20px 3px var(--primary-color) inset;
                border-radius: 50%;
                .icon {
                    color: var(--primary-color);
                    font-size: 52px;
                }
            }
        }
    }
}
</style>
